package com.formulas.certification.oauth.convertor;

import com.formulas.certification.domain.oauth.model.OauthClientDetailsEntity;
import com.formulas.certification.dto.data.OauthClientDetailsDTO;
import com.formulas.component.domain.ApplicationContextHelper;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author yiwannuofulasi
 * @date 2023/6/13 12:47
 */
@Mapper
public interface OauthClientDetailsConvertor {

    OauthClientDetailsConvertor INSTANCE = Mappers.getMapper(OauthClientDetailsConvertor.class);

    default OauthClientDetailsEntity toOauthClientDetailsEntity(OauthClientDetailsDTO oauthClientDetailsDTO){
        OauthClientDetailsEntity oauthClientDetailsEntity = ApplicationContextHelper.getBean(OauthClientDetailsEntity.class);
        oauthClientDetailsEntity.setClientId(oauthClientDetailsDTO.getClientId());
        oauthClientDetailsEntity.setClientName(oauthClientDetailsDTO.getClientName());
        oauthClientDetailsEntity.setClientSecret(oauthClientDetailsDTO.getClientSecret());
        oauthClientDetailsEntity.setAuthorities(oauthClientDetailsDTO.getAuthorities());
        oauthClientDetailsEntity.setAutoapprove(oauthClientDetailsDTO.getAutoapprove());
        oauthClientDetailsEntity.setAccessTokenValidity(oauthClientDetailsDTO.getAccessTokenValidity());
        oauthClientDetailsEntity.setRefreshTokenValidity(oauthClientDetailsDTO.getRefreshTokenValidity());
        oauthClientDetailsEntity.setAdditionalInformation(oauthClientDetailsDTO.getAdditionalInformation());
        oauthClientDetailsEntity.setResourceIds(oauthClientDetailsDTO.getResourceIds());
        oauthClientDetailsEntity.setScope(oauthClientDetailsDTO.getScope());
        oauthClientDetailsEntity.setAuthorizedGrantTypes(oauthClientDetailsDTO.getAuthorizedGrantTypes());
        oauthClientDetailsEntity.setWebServerRedirectUri(oauthClientDetailsDTO.getWebServerRedirectUri());
        return oauthClientDetailsEntity;
    }

    List<OauthClientDetailsDTO> toOauthClientDetailsDTOList(List<OauthClientDetailsEntity> oauthClientDetailsEntityList);

}
